package com.api.wall.getgroupevents;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.zyncro.api.IWallApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.CollectionResultApi;
import com.zyncro.api.model.EventApi;
import com.zyncro.api.model.EventApiType;
import com.zyncro.api.model.EventViewApiType;

@ContextConfiguration(locations = { "classpath:/wall/wall-static.xml" })
public class GetGroupEventsPrivateParticipant extends AbstractApiTest {

	@Value("#{group_toGetPrivate[participant].appId}")
	private String userUrn;

	@Value("#{group_toGetPrivate[participant].password}")
	private String userPassword;

	@Value("#{group_toGetPrivate.urn}")
	private String groupUrn;

	@Value("#{group_toGetPrivate.totalFeeds}")
	private int totalFeeds;

	@Value("#{group_toGetPrivate[owner].appId}")
	private String ownerUrn;

	@Value("#{group_toGetPrivate.ownerFeeds}")
	private int ownerFeeds;

	@BeforeClass
	protected void setParameters() throws Exception {

		getApi().login(userUrn, userPassword);
	}

	@Test
	public void testGroupFeedsAll() throws ZyncroApiException {

		String date = null;
		int itemsCount = 0;
		List<EventApiType> eventTypes = null;
		boolean includeHtml = false;
		EventViewApiType viewType = null;
		List<String> users = null;
		boolean includeProperties = false;

		CollectionResultApi<EventApi> result = getApi().getService(IWallApiService.class).getGroupEvents(groupUrn, date, itemsCount,
				eventTypes, includeHtml, includeProperties, viewType, users);

		Assert.assertEquals(result.getElements().size(), totalFeeds, "Total group feeds");
	}

	@Test
	public void testGroupFeedsTypes() throws ZyncroApiException {

		String date = null;
		int itemsCount = 0;

		List<EventApiType> eventTypes = new ArrayList<EventApiType>();
		eventTypes.add(EventApiType.CREATE_GROUP);

		boolean includeHtml = false;
		EventViewApiType viewType = null;
		List<String> users = null;
		boolean includeProperties = false;

		CollectionResultApi<EventApi> result = getApi().getService(IWallApiService.class).getGroupEvents(groupUrn, date, itemsCount,
				eventTypes, includeHtml, includeProperties, viewType, users);

		Assert.assertEquals(result.getElements().size(), 1, "Total create group feeds");
	}

	@Test
	public void testGroupFeedsViewType() throws ZyncroApiException {

		String date = null;
		int itemsCount = 0;
		List<EventApiType> eventTypes = null;

		boolean includeHtml = false;
		EventViewApiType viewType = EventViewApiType.CONVERSATION;
		List<String> users = null;
		boolean includeProperties = false;

		CollectionResultApi<EventApi> result = getApi().getService(IWallApiService.class).getGroupEvents(groupUrn, date, itemsCount,
				eventTypes, includeHtml, includeProperties, viewType, users);

		Assert.assertEquals(result.getElements().size(), totalFeeds, "Total create group feeds");
	}

	@Test
	public void testGroupFeedsUser() throws ZyncroApiException {

		String date = null;
		int itemsCount = 0;
		List<EventApiType> eventTypes = null;
		boolean includeHtml = false;
		EventViewApiType viewType = null;

		List<String> users = new ArrayList<String>();
		users.add(ownerUrn);
		boolean includeProperties = false;

		CollectionResultApi<EventApi> result = getApi().getService(IWallApiService.class).getGroupEvents(groupUrn, date, itemsCount,
				eventTypes, includeHtml, includeProperties, viewType, users);

		Assert.assertEquals(result.getElements().size(), ownerFeeds, "Total create group feeds");
	}
}
